﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
namespace PrintDrawing
{
    /// <summary>
    /// Interaction logic for setDataSource.xaml
    /// </summary>
    public partial class SetDataSource : UserControl
    {
        private Popup parent;
        public event btnOkClick onOkClick;
        public SetDataSource(Popup p)
        {
            InitializeComponent();
            parent = p;
        }
        private BaseClassDraw.TextBoxDrawn t;

        public void setProperty(BaseClassDraw.TextBoxDrawn txt)
        {
            t = txt;
            if (t._value!="" && t.NameColumn=="")
            {
                rdoValue.IsChecked = true;
            }
            else
            {
                rdoSource.IsChecked = true;
            }
            if (t.Text == "")
            {
                rdoSource.IsChecked = true;
            }            
            txtValue.Text = t._value;
            txtnameFeild.Text = t.NameColumn;
        }

        private void btnDongy_Click(object sender, RoutedEventArgs e)
        {
            if (rdoValue.IsChecked == true)
            {
                t.IsValue = true;
            }
            else
            {
                t.IsValue = false;
            }
            t.Text = txtValue.Text;
            t._value = txtValue.Text;
            t.NameTable = "";
            t.NameColumn = txtnameFeild.Text;
            parent.IsOpen = false;
            if (onOkClick != null)
            {
                onOkClick(this);
            }
        }
        
        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            parent.IsOpen = false;
        }

        private void loadSource(object sender, RoutedEventArgs e)
        {
            txtnameFeild.Focus();
        }
    }
    public delegate void btnOkClick(object sender);
}
